package com.muqi.app.qlearn.adapter;

import java.util.List;

import com.bumptech.glide.Glide;
import com.muqi.app.network.http.GlideImageUtils;
import com.muqi.app.project.utils.PictureUtil;
import com.muqi.app.project.utils.TimeMangerUtil;
import com.muqi.app.qlearn.modles.HomeWorkBean;
import com.muqi.app.qlearn.modles.PersonBean;
import com.muqi.app.qlearn.student.R;
import com.muqi.app.user.db.ChildBean;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.TextView;

public class ChildAdapter extends BaseAdapter {
	private Context context;
	private List<ChildBean> listData;
	private onBecomeVip becomeVip;
	

	public void setBecomeVip(onBecomeVip becomeVip) {
		this.becomeVip = becomeVip;
	}

	public ChildAdapter(Context context, List<ChildBean> listData) {
		this.context = context;
		this.listData = listData;

	}

	@Override
	public int getCount() {
		return listData == null ? 10 : listData.size();
	}

	@Override
	public ChildBean getItem(int position) {
		return listData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		final ChildBean itemInfo = listData.get(position);
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_child, null);
			holder.itemAvatar = (ImageView) convertView
					.findViewById(R.id.item_avator);
			holder.itemVip = (ImageView) convertView
					.findViewById(R.id.iv_vip);
			holder.itemName=  (TextView) convertView
					.findViewById(R.id.item_name);
			holder.itemVipInfo=(TextView) convertView
					.findViewById(R.id.item_vip_info);
			holder.itemVipTime=(TextView) convertView
					.findViewById(R.id.item_vip_time);
			holder.itemBecomVip= (Button) convertView.findViewById(R.id.item_become_vip);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (itemInfo != null) {
			
				GlideImageUtils.setAvatar(context,
						itemInfo.avatar_02, holder.itemAvatar);
				holder.itemName.setText(itemInfo.name);
				holder.itemBecomVip.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View arg0) {
						if(becomeVip!=null){
							Log.e("===", itemInfo.child_id);
							becomeVip.becomeVip(itemInfo.child_id);
						}
					}
				});
				
		}

		return convertView;
	}

	private class ViewHolder {
		ImageView itemAvatar;
		TextView itemName;
		TextView itemVipInfo;
		TextView itemVipTime;
		Button itemBecomVip;
		ImageView itemVip;

	}
	public interface onBecomeVip{
		public void becomeVip(String studentId);
	}

}
